{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ed5fbade",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "42bf4829",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取文件\n",
    "df1 = pd.read_csv('年度数据.csv',index_col=0,encoding='gb2312')\n",
    "#df1 = df1.head()\n",
    "#df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a27e0fb3",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df1[['2021年','2012年']]\n",
    "#df1.iloc[:2,2:]\n",
    "#df1.loc['居民人均消费支出比上年增长(%)':'居民人均服务性消费支出(元)','2018年':'2015年']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1b1ba396",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 10)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.shape #查看数据大小，返回一个元祖（行数,列数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "99bda988",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df2 = df1.reindex([1,2,3,4,0]) # 更改索引顺序，列表为已经存在的索引\n",
    "#print(df1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "359b37c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df1 #Not a Number 不是一个数字，空数字\n",
    "#df1.isnull()\n",
    "#df1.dropna(axis=0,how='any',thresh=None) # 删除NaN值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "fc6c345c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df1 = df1.fillna(method='ffill',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "05dc2228",
   "metadata": {},
   "outputs": [],
   "source": [
    "#df1 = df1.fillna(method='bfill',axis=1)\n",
    "#df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0665e5f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = df1.T\n",
    "#df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c1679202",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.86\n",
      "9.1\n"
     ]
    }
   ],
   "source": [
    "df2 = df1.loc['2021年':'2016年']\n",
    "df3 = df1.loc['2016年':'2012年']\n",
    "print(df2['居民人均生活用品及服务支出比上年增长(%)'].mean())\n",
    "print(df3['居民人均生活用品及服务支出比上年增长(%)'].mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9a8a1175",
   "metadata": {},
   "outputs": [],
   "source": [
    "#1. 上节课下载的数据，查看数据大小\n",
    "#2. 数据预处理，NaN，查看是否存在NaN,如果不存在，也要写查看的代码，NaN值填充\n",
    "#3. 对数据进行预览的describe\n",
    "#4. 选自己感兴趣的部分进行切片，至少去输出最大、最小、平均、和的其中一项"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
